<template>
    <!--左侧房源筛选-->
    <div class="lefMain">
        <!--左侧1-->
        <span class="leftTop">
            <span style="font-size: 18px;white-space: nowrap;color:#7a8df1;font-weight: 600;">
                {{ $t('text.Contract.l73') }}
            </span>
            <DialogLayout59 @returnData="search()">
                <span class="df">
                    <img class="addImg" src="../../assets/images/add.svg">
                    <div style="font-size: 13px;white-space: nowrap;">{{ $t('text.Contract.l65') }}</div>
                </span>
            </DialogLayout59>
            
        </span>

        <!--左侧3-->
        <div>
            <div class="leftTopInput">
            <img class="img1" src="../../assets/images/search2.png" />
            <input :placeholder="$t('text.Contract.l74')" class="leftTop2Input" v-model="nameOrNo">
        </div>
            <div class="leftTop2">

                <div class="df">
                    <img class="img2" src="../../assets/images/icon.png" />
                    <div class="time">
                        {{ $t('text.Contract.l66') }}
                        <el-date-picker v-model="time" type="month" :placeholder="$t('text.Employee.l26')"
                            style="width: 100px;margin-left: 10px;height: 23px;font-size: 12px;" value-format="YYYY-MM" />
                    </div>
                </div>

                <div class="df">
                    <img class="img2" src="../../assets/images/icon.png" />
                    <div class="items">
                        <RadioSelect :leftText="$t('text.Contract.l76')" :selectList="orgTreeList" searchKey="orgIds"
                            isShowTitle @returnData="setData" @clearData="clearData" isRange2 :isReset="isReset">
                        </RadioSelect>
                    </div>
                </div>
                <div class="df">
                    <img class="img2" src="../../assets/images/icon.png" />
                    <div class="items">
                        <RadioSelect :leftText="$t('text.Contract.l77')" :selectList="getSelectData('userRewardType')"
                            searchKey="isReward" isSingle @returnData="setData" :isReset="isReset"
                            @clearData="clearData">
                        </RadioSelect>
                    </div>
                </div>
                <div class="df">
                    <img class="img2" src="../../assets/images/icon.png" />
                    <div class="items">
                        <RadioSelect :leftText="$t('text.Contract.l78')" :selectList="getSelectData('financeExamineStatus')"
                            searchKey="examineStatus" isSingle @returnData="setData"
                            :isReset="isReset" @clearData="clearData">
                        </RadioSelect>
                    </div>
                </div>

            </div>
        </div>
        <div class="resetDiv" @click="reset">{{ $t('text.Contract.l32') }}</div>

    </div>

    <!--右侧房源列表-->
    <div class="rightMain">
        <!--右侧顶部导航-->
        <div class="rightTop">
            <div></div>
            <div></div>
            <div class="out"><img class="outImg" src="../../assets/images/out.svg"><span>{{ $t('text.Employee.l7') }}</span>
            </div>
        </div>
        <!--右侧房源数据列表-->
        <div class="rightContain">

            <table class="rightList" v-if="resultList.length > 0">
                <tr class="eDataList" v-for="item in resultList" v-bind:key="item">
                    <td class="dataDom" style="margin-top: -5px;flex: 2;">
                        <div class="dataTitle">
                            <CommonImage :src="item.avatar" class="imgStyle" />
                            {{ item.sysUserName == null ? '-' : item.sysUserName }}&emsp;
                            <span :class="'tag' + item.examineStatus">
                                {{ item.examineStatus == '0' ? $t('text.Contract.l71') : '' }}
                                {{ item.examineStatus == '1' ? $t('text.Contract.l347') : '' }}
                            </span>
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle">
                            <span
                                :style="item.isReward == 0 ? { color: '#f68686', whiteSpace: 'nowrap' } : { color: '#54d2d0', whiteSpace: 'nowrap' }">
                                {{ item.isReward == 0 ? '-' : '+' }}
                                {{ item.price == null ? '-' : String(item.price).replace(/\B(?=(\d{3})+(?!\d))/g, ',') }}
                            </span>
                        </div>
                    </td>
                    <td class="dataDom" style="margin: 0 5px;margin-left: 20px;flex: 1.3;">
                        <div class="dataTitle" style="white-space: pre-wrap;">
                            {{ item.orgName == null ? '-' : item.orgName }}&ensp;-&ensp;
                            {{ item.jobName == null ? '-' : item.jobName }}
                        </div>
                    </td>
                    <td class="dataDom" style="margin: 0 15px;margin-left: 20px;flex: 1.5;">
                        <div class="dataTitle">
                            <CommonOmit :text="item.notes == null || item.notes == '' ? '-' : item.notes" :length="2">
                            </CommonOmit>
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle">
                            {{ item.time == null ? '-' : item.time }}
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataTitle">
                            {{ item.updateByName == null ? '-' : item.updateByName }}
                        </div>
                    </td>
                    <td class="dataDom">
                        <div class="dataImg">
                            <DialogLayout59 isEdit v-if="item.examineStatus == '0'" @returnData="search()" :data="item">
                                <img src="../../assets/images/h68.svg" class="dataImgIcon">
                            </DialogLayout59>
                            <DialogLayout56 isPeople :id="item.id" v-if="item.examineStatus == '0'" @returnData="search()">
                                <img src="../../assets/images/h69.svg" class="dataImgIcon">
                            </DialogLayout56>
                            <DialogLayout57 isPeople :id="item.id" v-if="item.examineStatus == '0'" @returnData="search()">
                                <img src="../../assets/images/h70.svg" class="dataImgIcon">
                            </DialogLayout57>
                            <DialogLayout58 isPeople :id="item.id" v-if="item.examineStatus == '1'" @returnData="search()">
                                <img src="../../assets/images/h71.svg" class="dataImgIcon">
                            </DialogLayout58>
                        </div>
                    </td>
                </tr>
            </table>
            <div class="rightList" v-else>
                <div class="nulData">
                    {{ $t('text.Common.l67') }}
                </div>
            </div>
            <!--底部分页-->
            <div class="setPage">
                <el-pagination v-model:current-page="searchData.pageNo" v-model:page-size="searchData.pageSize"
                    :page-sizes="[10, 15, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper" :total="total"
                    @size-change="handleSizeChange" @current-change="handleCurrentChange" />
            </div>
        </div>
    </div>
</template>
    
<script>
import CommonImage from "@/components/input/CommonImage.vue"
import RadioSelect from "../../components/select/RadioSelect.vue"
import { userRewardGetDrop, userRewardFindPage, userGetOrgTree } from "../../http/api"
export default {
    name: "EmployeeRewards",
    components: {
        RadioSelect,
        CommonImage,
    },
    data() {
        return {
            searchData: {
                pageNo: 1,
                pageSize: 15,
            },
            dictionaryTree: {},
            isReset: false,
            resultList: [],
            total: 0,
            orgTreeList: [],
            time: "",
            nameOrNo:""
        }
    },
    mounted() {
        userRewardGetDrop().then(res => {
            if (res !== undefined) {
                this.dictionaryTree = res
                console.log(res)
                userGetOrgTree({perm:'find_user_reward',type:7}).then(res => {
                    if (res !== undefined) {
                        this.orgTreeList = res
                        console.log(res)
                    }
                }).catch()
            }
        })
        this.search()
    },
    methods: {
        //获取字典数据
        getSelectData(key) {
            const data = this.dictionaryTree[key]
            if (data != undefined) {
                return this.dictionaryTree[key]
            } else {
                return [
                    {
                        dictName: "全部",
                        dictValue: "-1",
                    },
                ]
            }
        },

        //搜索数据
        search() {
            userRewardFindPage(this.searchData).then(res => {
                if (res !== undefined) {
                    this.resultList = res.dataList
                    this.total = res.total
                    console.log(res)
                }
            }).catch()
        },

        //拼接单个子组件返回来的条件值
        setData(obj) {
            this.searchData = { ...this.searchData, ...obj }
            console.log(JSON.stringify(this.searchData))
        },

        //子组件选择了不限，进行删除指定字段
        clearData(obj) {
            const objKeys = Object.keys(obj)
            this.searchData = Object.keys(this.searchData).reduce((acc, key) => {
                if (!objKeys.includes(key)) {
                    acc[key] = this.searchData[key]
                }
                return acc
            }, {})
            console.log(JSON.stringify(this.searchData))
        },

        //重置
        reset() {
            this.searchData = {
                pageNo: 1,
                pageSize: 15,
            }
            this.time = ''
            this.isReset = !this.isReset
        },
        handleSizeChange(val) {
            this.searchData.pageSize = val
            this.search()
        },
        handleCurrentChange(val) {
            this.searchData.pageNo = val
            this.search()
        },
    },
    watch: {
        searchData: {
            handler() {
                this.search()
            },
        },
        time() {
            if (this.time == null) {
                this.clearData({ time: "" })
            } else {
                let obj = { time: this.time }
                this.searchData = { ...this.searchData, ...obj }
            }
        },
        nameOrNo() {
            let obj = { nameOrNo: this.nameOrNo }
            this.setData(obj)
        },
    },
    computed: {},
}
</script>
    
<style scoped>
.dataImg {
    display: flex;
    align-items: center;
}

.dataImgIcon {
    width: 22px;
    height: 22px;
    margin-left: 10px;
}

.imgStyle {
    min-width: 35px;
    width: 35px;
    height: 35px;
    border-radius: 100%;
    margin-right: 15px;
}

.nulData {
    background-image: url("../../assets/images/nullData.svg");
    background-size: cover;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 25px;
    color: #979797;
}

.tag0 {
    border: 1px solid #f7ad53;
    padding: 0 10px;
    margin-right: 10px;
    border-radius: 4px;
    background: #f7ad5329;
    color: #f7ad53;
    font-size: 12px;
    white-space: nowrap;
}

.tag1 {
    border: 1px solid #54d2d0;
    padding: 0 10px;
    margin-right: 10px;
    border-radius: 4px;
    background: #54d2d029;
    color: #54d2d0;
    font-size: 12px;
    white-space: nowrap;
}

.resetDiv {
    background: #6698ff;
    margin-top: 20px;
    padding: 5px 0;
    font-size: 13px;
    color: white;
    border-radius: 7px;
}

.df {
    display: flex;
    align-items: center;
    margin-top: 8px;
    margin-bottom: 2px;
}

.lefMain {
    min-width: 310px;
    padding: 15px;
    overflow: auto;
    background: white;
    margin-bottom: 30px;
    margin-right: 5px;
    box-shadow: 1px 10px 30px 4px #e9e9e9;
}

.rightContain {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    background: white;
    margin: 20px 30px 30px 25px;
    position: relative;
    box-shadow: 1px 5px 10px 4px #e9e9e9;
}

.leftTop {
    color: #6698ff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.leftTop2 {
    border: 1px solid #cecece;
    border-radius: 5px;
    padding: 10px;
    margin-top: 10px;
    position: relative;
    padding-top: 0;
}

.img2 {
    width: 22px;
    height: 22px;
}

.items {
    margin-left: 15px;
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 12px;
    color: gray;
    border-bottom: 1px solid rgb(224, 224, 224);
    width: 100%;
}

.rightMain {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #f8f8f8;
}

.rightList {
    height: 100%;
    display: flex;
    flex-direction: column;
    border-radius: 5px;
    overflow: auto;
    padding: 20px 0;
}

.rightTop {
    display: flex;
    padding-top: 15px;
    align-items: center;
    justify-content: space-between;
    padding-right: 32px;
}

.addImg {
    width: 15px;
    height: 15px;
    padding-right: 3px;
}

.setPage {
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid #eee;
    padding: 10px;
}

.out {
    display: flex;
    align-items: center;
    font-size: 14px;
}

.outImg {
    width: 20px;
    height: 20px;
    padding-right: 5px;
}

.img2 {
    width: 22px;
    height: 22px;
}

.time {
    margin-left: 15px;
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 12px;
    color: gray;
    border-bottom: 1px solid rgb(224, 224, 224);
    width: 100%;
    display: flex;
    align-items: center;
    white-space: nowrap;
    justify-content: space-between;
}

.eDataList {
    display: flex;
    align-items: flex-start;
    padding: 5px 30px;
    margin: 3px 0px;
    position: relative;
}

.eDataList::after {
    position: absolute;
    content: "";
    width: calc(100% - 60px);
    height: 1px;
    bottom: 0;
    border-bottom: 1px solid #eee;
    padding: 1px;
    margin-right: 30px;
}

.eDataList:hover {
    background: #eee;
}

.dataTitle {
    font-size: 13px;
    color: #1f1f1f;
    display: flex;
    min-height: 22px;
    align-items: center;
    word-break: break-all;
}

.dataValue {
    font-size: 13px;
    color: #5c5c5c;
}

.dataDom {
    flex: 1;
    text-align: left;
    padding: 10px 0;
    display: flex;
    width: 14%;
}

.dataDom:first-child,
.dataDom:nth-child(3),
.dataDom:nth-child(2) {
    justify-content: flex-start;
}

.dataDom:last-child {
    justify-content: flex-end;
    padding-right: 10px;
}
.leftTopInput {
    display: flex;
    width: 100%;
    position: relative;
    padding-top: 10px;
}

.img1 {
    position: absolute;
    left: 7px;
    width: 15px;
    height: 15px;
    top: 17px;
    z-index: 1;
}

.leftTop2Input {
    outline: none;
    width: inherit;
    height: 25px;
    border: 1px solid rgb(220, 223, 230);
    padding-left: 23px;
    padding-right: 20px;
    background-color: rgb(242, 242, 242);
    border-radius: 5px;
    font-size: 12px;
    position: relative;
}
</style>